'use strict';{const x=[],y=_Ow(600,()=>{const b=_Ky.notifications;b.getAll(c=>{3<Object.keys(c).length&&x.length&&(b.clear(x[0]),y())})});let E=_wj(function*(b,c){const a=_Ky.notifications;if(!c||!a)return _Qu;b=b.slice(0,100);const m={type:"basic",contextMessage:"DOWNLOADING...",message:b,title:"",iconUrl:"data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA="};70<=_Ok&&(m.silent=!0);let g;const n=h=>{m.add(h);"progress"!=m.type&&delete m.progress;_nd(function*(){for(;g;)yield _Pi(0);g=!0;(yield d=>
a.update(k,h,d))||(k=yield d=>a.create(m,d));g=!1})},e=[{title:"Open"},{title:"Show in folder"}];let k=yield h=>a.create(m,h),l,f;return(h,...d)=>{switch(h){case "started":{let [p,r]=d;l=p;r&&(f=r,n({contextMessage:`DOWNLOADING (${_jj(f.contentSize)}B)`,message:b}));break}case "progress":h={contextMessage:`DOWNLOADING (${_jj(f.contentSize||f.loadedSize)}B)`};n(f.contentSize?h.add({type:"progress",progress:100*f.loadedSize/f.contentSize|0}):h);break;case "interrupt":[h]=d;n({type:"basic",contextMessage:`INTERRUPTED (${_jj(f.loadedSize)}B${f.contentSize?
` / ${_jj(f.contentSize)}B`:""})`,message:`${h}\n${b}`});break;case "saving":n({contextMessage:`SAVING (${_jj(f.loadedSize)}B)`,message:l});break;case "fileExists":case "done":{n({type:"basic",contextMessage:("done"==h?"SAVED":"File already exists")+` (${_jj(f.contentSize||f.loadedSize)}B)`,message:l,buttons:e});const p=["onButtonClicked","onClosed"];function r(q,t){q==k&&("number"==typeof t&&(0==t&&_Od(`"${l}"`)(),1==t&&_Od(`cmd /c start "" "${l.replace(/[^\\]+$/,"")}"`)(),a.clear(k)),_Ki(a,p,r),
x.remove(k))}_5g(a,p,r);y();setTimeout(()=>{x.push(k);y()},1300);break}case "httpError":[h]=d;n({contextMessage:"ERROR",message:`${_1k(h.status,h)}\n${b}`});break;case "fileError":[h]=d;n({type:"basic",contextMessage:"ERROR",message:`${h.trim()}\n${l}`});break;case "clear":a.clear(k)}}}),z=(b,c)=>a=>{let m=["All Files: *.*"];c&&(c=c.slice(1).toLowerCase(),m.unshift(`${c.toUpperCase()} files (.${c}): *.${c}`));_Rp(b,m.join(", "),!0)(a)},A=(b,c)=>a=>{const m=/^(.*?)(\.[^.]*)?$/;let [,g,n=""]=b.match(m);
c(g,n)(e=>{e=(e[0]||"").trim()||b;[,,n=""]=e.match(m);a([e,n])})},F=_wj(function*(b,c,a,m,g,n,e){var k=_Kw(b);let [l,f]=yield A(k,a);a=B(c,l);e("started",a,b);k=!1;let h=+new Date(b.getResponseHeader("last-modified"));if(c)for(let p=1,r=a;;++p){var d=yield _fw(_De,{path:a});if(d&&!d.error)if(d=d.size==b.contentSize&&d.modTime==h?g:n,"rename"==d){a=r.replace(/(\.[^.]+)?$/,` (${p})$1`);e("started",a);continue}else if(!m)if("cancel"==d)e("fileExists"),k=!0;else if("ask"==d){a=yield z(a,f);if(!a)return[,
,!0];e("started",a)}break}if(m||!c)if(a=yield z(a,f),!a)return[,,!0];return[a,h,k]}),C=(b,c,a,m)=>{a.abort();_ok(c,"",void 0,!0);_So(_r,b,g=>m("fileError",g))},I=(b,c,a,m,g,n,e,k)=>l=>_nd(function*(){const f=yield E(b,e),h=yield(79>_Ok&&!b.startsWith("data:")?G:H)(b);let d=0;if(200!=h.status)f("httpError",h),d++||l(),k(void 0);else{var [p,r,q]=yield F(h,c,a,m,g,n,f);q&&!p&&f("clear");if(q)h.abort();else for(;;){try{var t=yield h.readBody()}catch(u){f("interrupt",u.message);d++||l();k(void 0);return}if(t.done){f("saving");
if(t=yield _ok(p,t.value,void 0,void 0,r)){C(t,p,h,f);d++||l();k(void 0);return}f("done");break}f("progress");let w=yield _ok(p,t.value,void 0,void 0,void 0,!0);d++||l();if(w){C(w,p,h,f);d++||l();k(void 0);return}}d++||l();k(p)}}),v;const D=(b,c)=>{if(v[b.id])return v[b.id](b,c),!0};let J=(b,c,a,m,g,n)=>e=>{const k=_Ky.downloads;let l=0;if(k){var f,h,d,p;k.onChanged.addListener(function t(q){if(q.id==f){if(q.filename){d=q.filename.current;if("cancel"==g&&!m){let [,w,u]=d.match(/^(.+?)([^\\]+)$/);
u!=h&&(d=w+h,p=!0,k.cancel(f),k.erase({id:f}))}l++||e()}(q=q.state)&&q.current.in("complete","interrupted")&&(k.onChanged.removeListener(t),q="complete"==q.current||p?d:null,l++||e(),n(q))}});v||(v={},k.onDeterminingFilename.addListener(D));k.download({url:b,saveAs:!!m},q=>{f=q;v[f]=(t,w)=>{A(t.filename,a)(([u])=>{h=u;c.match(/^[\/\\]|:/)||(u=B(c,u));w({filename:u,conflictAction:{rename:"uniquify",cancel:"uniquify",ask:"prompt"}[g]||"overwrite"});delete v[f];_Pt(v)&&(v=void 0,k.onDeterminingFilename.removeListener(D))})}})}else l++||
e(),n(void 0)},B=(...b)=>b.filter(c=>c).join("\\").replace(/[\/\\]+/g,"\\");const K=_Ow(250,b=>_So(_Op,{sysEvent:b})),L=(b,c,a)=>(m,g)=>{const n=new Proxy(c,{get(e,k){let l=k.toLowerCase();return"filename"==l?m:"fileext"==l?g:e[k]}});return _fr(a,_6s,b,n)};var _F=_wj(function*(b,c,a){const m=_Mu(c.url||""),g=_Mu(c.folder||""),n=_Mu(c.file||""),e=[];let k=d=>{"audio"==c.method&&K(d?"SystemAsterisk":"SystemHand");if(d)switch(c.doAtEnd){case "open":_Od(`"${d}"`)();break;case "openDir":_Od(`cmd /c start "" "${d.replace(/[^\\]+$/,
"")}"`)();break;case "copy":e.push(d)}};_Wd();let l=new _do;for(let d of c.usesTabs?_Nd(b):[0]){b=_os[d]||{};var f=yield _fr(a,_6s,m,b);for(let p of f)if((p=p.trim().match(/^.*/)[0].trim())&&_Zk(p)){var h=b.sc().add({url:p});f=L(n,h,a);h=yield _fr(a,_6s,g,h);for(let r of h)r=r.trim(),"dwnlApi"==c.method?yield J(p,r,f,c.showSaveAs,c.ifNameExist,l.onReady(k)):yield I(p,r,f,c.showSaveAs,c.ifFileExist,c.ifNameExist,"notif"==c.method,l.onReady(k))}}yield d=>l.setCallback(d);"copy"==c.doAtEnd&&(yield d=>
_Tp(c.tgtClpbrd,e.join("\n"),!1,d))});let G=(b,c)=>a=>{let m=!0,g,n,e=new XMLHttpRequest;e.open("GET",b);e.responseType="blob";e.onerror=()=>{g="";a(e)};e.loadedSize=0;let k=()=>{if(n){const l=n;n=null;l(null!=g?{done:!0,value:g}:{value:""})}};e.onload=function(){m&&(e.loadedSize=e.contentSize=+e.getResponseHeader("Content-Length"),a(e));_1f(this.response)(l=>{g=l;k()})};e.onprogress=l=>{e.contentSize=l.total;e.loadedSize=l.loaded;m?(m=!1,a(e)):k()};e.readBody=()=>l=>{n=l;null!=g&&k()};e.send()},
H=_wj(function*(b,c){try{c=g=>({requestHeaders:g.requestHeaders.concat({name:"Referer",value:_Th(b)||_uj(b)})});for(let g=0;2>g;++g){_Ky.webRequest.onBeforeSendHeaders.addListener(c,{urls:[b]},["requestHeaders","extraHeaders","blocking"]);var a=yield fetch(b,{redirect:"follow",mode:"cors",credentials:"include",cache:"force-cache",referrerPolicy:"unsafe-url"});_Ky.webRequest.onBeforeSendHeaders.removeListener(c);if(300<=a.status)b=a.url;else break}let m=a.body.getReader();return a.add({loadedSize:0,
contentSize:+a.headers.get("Content-Length"),responseURL:a.url,abort:()=>{m.releaseLock();a.body.cancel()},getResponseHeader:g=>a.headers.get(g),readBody:_wj(function*(){let g=yield m.read();g.value=g.value?yield _1f(new Blob([g.value])):"";a.loadedSize+=g.value.length;return g})})}catch(m){}return{}})};
